import { floatToFixed2 } from '@/utils'

// 格式化金额【分转元】
// @ts-ignore
export const fenToYuanFormat = (_, __, cellValue: any, ___) => {
  return `￥${floatToFixed2(cellValue)}`
}

/**
 *  将 html 字符串中的标签去掉
 * @param html // html 字符串
 * @returns
 */
export const extractTextFromHTML = (html) => {
  return html.replace(/<[^>]+>/g, '').replace(/&[^;]+;/g, '')
}

export function toFixed(number, precision) {
  const multiplier = Math.pow(10, precision + 1),
    wholeNumber = Math.floor(number * multiplier)
  return (Math.round(wholeNumber / 10) * 10) / multiplier
}
export function pxToViewport(val, viewportUnit = 'vw') {
  const pixels = parseFloat(val)
  const parsedVal = toFixed((pixels / 1920) * 100, 5)
  return parsedVal === 0 ? '0' : parsedVal + viewportUnit
}

export function getViewportPx(val, hiddenPx = false) {
  const pixels = parseFloat(val)
  const parsedVal = toFixed(window.innerWidth * (pixels / 1920), 5)
  return parsedVal === 0 ? '0' : parsedVal + (hiddenPx ? '' : 'px')
}
